package com.wsm.common.utils;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.io.Serializable;

/**
 * @name: ResultData
 * @Author: wangshimin
 * @Date: 2020/2/3  20:28
 * @Description:json结果集
 */
@Data
@AllArgsConstructor
public class Result<T> implements Serializable {
    //成功
    private static final String success = "1";
    //系统异常
    private static final String error = "-1";
    //业务异常
    private static final String exception = "0";

    //执行状态
    private String status;
    //代码
    private String code;
    //信息
    private String msg;

    //数据json
    private T data;

    public Result() {
        status = success;
        msg = "执行成功";
    }

    //success
    public static <T> Result<T> success() {
        return new Result<T>(success, null, "执行成功", null);
    }

    public static <T> Result<T> success(T data) {
        return new Result<T>(success, null, "执行成功", data);
    }

    public static <T> Result<T> successMsg(String successMsg) {
        return new Result<T>(success, null, successMsg, null);
    }

    public static <T> Result<T> successMsg(String code, String successMsg) {
        return new Result<T>(success, code, successMsg, null);
    }

    public static <T> Result<T> success(String msg, T data) {
        return new Result<T>(success, null, msg, data);
    }

    public static <T> Result<T> success(String code, String msg, T data) {
        return new Result<T>(success, code, msg, data);
    }

    //error
    public static <T> Result<T> error() {
        return new Result<T>(error, null, "系统异常", null);
    }

    public static <T> Result<T> error(T data) {
        return new Result<T>(error, null, "系统异常", data);
    }

    public static <T> Result<T> errorMsg(String errorMsg) {
        return new Result<T>(error, null, errorMsg, null);
    }

    public static <T> Result<T> errorMsg(String code, String errorMsg) {
        return new Result<T>(error, code, errorMsg, null);
    }

    public static <T> Result<T> error(String msg, T data) {
        return new Result<T>(error, null, msg, data);
    }

    public static <T> Result<T> error(String code, String msg, T data) {
        return new Result<T>(error, code, msg, data);
    }

    //deny
    public static <T> Result<T> deny() {
        return new Result<T>(exception, null, "执行失败", null);
    }

    public static <T> Result<T> deny(T data) {
        return new Result<T>(exception, null, "执行失败", data);
    }

    public static <T> Result<T> denyMsg(String denyMsg) {
        return new Result<T>(exception, null, denyMsg, null);
    }

    public static <T> Result<T> denyMsg(String code, String denyMsg) {
        return new Result<T>(exception, code, denyMsg, null);
    }

    public static <T> Result<T> deny(String msg, T data) {
        return new Result<T>(exception, null, msg, data);
    }

    public static <T> Result<T> deny(String code, String msg, T data) {
        return new Result<T>(exception, code, msg, data);
    }
}
